#ifndef __EGL__IMPL__H__
#define __EGL__IMPL__H__

#include "BaseEgl.h"
#ifdef __ANDROID__
#include <jni.h>
#endif
#include <mutex>

namespace simple_renderer{

class EglImpl : public BaseEgl{

public:
    EglImpl();
    virtual ~EglImpl();

    virtual int InitGLEnv() override;
    virtual int Release() override;
//#ifdef __ANDROID__
    virtual int SetAndroidView(std::shared_ptr<JavaGlobalRef<jobject>> frame_window_ref) override;
    virtual int ResetAndroidView() override;
//#endif

    virtual int CreateSurface() override;
    virtual int DestorySurface() override;

    virtual int MakeCurrent() override;
    virtual int EGLSwap() override;
    virtual int DetachCurrent() override;

    virtual int SetSurfaceSize(int w, int h) override;

    virtual bool IsEglValidate() override;
    virtual bool HasContext() override;

    virtual int GetWidth() override;
    virtual int GetHeight() override;

    bool IsEnvReleased() override{
        return _is_env_released;
    }

protected:
    int GetSurfaceWidth();
    int GetSurfaceHeight();

protected:

    EGLNativeWindowType _window;

    EGLDisplay _display;
    EGLSurface _surface;
    EGLContext _context;

    EGLint _width;
    EGLint _height;

    std::mutex _vout_mux;

    bool _is_env_released;

#ifdef __ANDROID__
    std::shared_ptr<JavaGlobalRef<jobject>> _frame_window_ref;
#endif
};

}
#endif